<template>
  <div class="userEdit">
    <el-table :data="tableData" class="H100" maxHeight="650">
      <el-table-column label="日期" width="150">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.date | date}}</span>
        </template>
      </el-table-column>
      <el-table-column label="昵称" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.username }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.age }}</span>
        </template>
      </el-table-column>
      <el-table-column label="性别" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.sex==0?'女':'男' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电话" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="QQ" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.qq }}</span>
        </template>
      </el-table-column>
      <el-table-column label="WeiXin" width="170">
        <template slot-scope="scope">
          <span>{{ scope.row.weixin }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="danger" size="mini" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  export default {
    created() {
      this.getUserList()
    },
    data() {
      return {
        tableData: [],
        isDetele: false,
        visible: false
      }
    },
    methods: {
      async getUserList() {
        const result = await this.api.get('/admin/getUserList')
        this.tableData = result.data
      },
      deteleUserById(id) {
        this.api.get('/admin/deteleUserById', {
          params: {
            id: id
          }
        }).then(res => {
          if(res.code ==0){
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.getUserList()
          }else {
            this.$message({
              message: '删除失败',
              type: 'success'
            })
          }
        }).catch(err => {
          console.log(err)
        })
      },
      handleDelete(index, row) {
        this.deteleUserById(row._id)
      },
    }
  }
</script>

<style>

</style>